<?php 
/*
* ----------------------------------------------------------------------------------------------------
* Create Post Type For Portfolio
* @PACKAGE BY THEMECENTER.NET
*
* menu_position
* 5 - below Posts 
*10 - below Media 
*15 - below Links 
*20 - below Pages 
*25 - below comments 
*60 - below first separator 
*65 - below Plugins 
*70 - below Users 
*75 - below Tools 
*80 - below Settings 
*100 - below second separator 
*
* ----------------------------------------------------------------------------------------------------
*/
function relasted_portfolio_style_1($title='',$num_of_post='6',$light_box='',$sort='')
{
wp_enqueue_script('prettyPhoto');
//Numofpost
//lightbox
//sort
/* For portfolio style 2
//style
	   //if style portfolio style 2
	   		//enable title
			//readmore
			//Numofchacter
			//showdesc
*/
$types=get_the_terms(get_the_ID(), 'portfolio-types');
if($light_box == ''):
    $light_box = get_theme_option('portfolio','portfolio_enable_lightbox_related');
endif;
if($num_of_post == '') :
$num_of_post = get_theme_option('portfolio','portfolio_single_number_related_post');
endif;
if($sort == ''):
$sort = get_theme_option('portfolio','portfolio_sort');
endif;
  $return ='';
if($types):
  foreach($types as $type):
  	$slugs[$i]=$type->slug;
  	$i++;
  endforeach;
  $args= array(
  	   		'tax_query' =>array(
         			array(
  				'taxonomy' => 'portfolio-types',
         			'field' => 'slug',
         			'terms' =>$slugs
  				),
         		 ),
  			 'showposts' =>$num_of_post,
  			 'orderby' =>'id',
  			 'order' => $sort,
  			 'post_type' => 'portfolio'
  			 );
  global $posts;  
  $posts = new WP_Query( $args );
  
  

  if( $posts->have_posts()):
  	
	  		if($title <> ''):
			
			$return.='
        		   <div class="right-inner">
                        <h2 class="head">'.$title.'</h2>
            	   </div>';
			endif;	  
	  global $posts;
      $curr_count=0;
      $sum = 0;		
	  					$return.='<div class="home-blog">
						 <ul id="portfolio-list">';		
  	  while($posts->have_posts()): $posts->the_post();

            $image = get_meta_option('image_upload_portfolio',get_the_ID());
            $video = get_meta_option('video_embed_code',get_the_ID());
            $video_embed=get_meta_option('video_embed_code',get_the_ID());
            $youtube_video = get_meta_option('youtube_id',get_the_ID());
            $vimeo_video = get_meta_option('vimeo_id',get_the_ID());
            $video_style = get_meta_option('video_style',get_the_ID());
            $direct_link = get_meta_option('direct_url_portfolio',get_the_ID());
			$sum++;
            $image_thumb = '';
            if(has_post_thumbnail(get_the_ID())):
                $images_id=get_post_thumbnail_id(get_the_ID());
                $image_thumb=wp_get_attachment_image_src($images_id,'194-148');
          		$type_portfolio = get_meta_option('portfolio_type',get_the_ID());
            endif;
			  $types_portfolio=get_the_terms(get_the_ID(),'portfolio-types');
              $types_portfolio_arr = array();
              $num=0;
              if($types_portfolio) :
                 foreach($types_portfolio as $type):
                    $types_portfolio_arr[$num]=str_replace(' ','-',$type->name);
                    $num++;
                 endforeach;
             endif;

                           $return.='   <li class="'.implode(' ',$types_portfolio_arr).'">
                                  <div class="port-shadow">
                                    <div class="mosaic-block bar2">
                                        <div class="mosaic-overlay">
                                            <div class="details">
                                                <h2>'.get_the_title().'</h2>';
												
  											   if($light_box=='true'): 
          											   if($type_portfolio=='1') : $image_upload=get_meta_option('image_upload_portfolio',get_the_ID());
                                                         $return.='<div><a rel="prettyPhoto" class="zoom-icon" href="'.$image_upload.'" title="'.get_the_title().'">&nbsp;</a> <a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
          											  elseif($type_portfolio=='2') :
                                                         if($video_style =="embed") :
                                  						
                          						   	    
  														$return.='<div><a rel="prettyPhoto" class="video-icon"   href="#video'.$sum.'" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                                  						
                          								elseif($video_style =="youtube") :
                          								
                          								
                          						  		 $return.='<div><a rel="prettyPhoto" class="video-icon"   href="http://www.youtube.com/watch?v='.$youtube_video.'" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                          								
                          								elseif($video_style =="vimeo") :
                          								
                          								
                          						   		$return.='<div><a href="http://vimeo.com/'.$vimeo_video.'"  class="video-icon" rel="prettyPhoto" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                      									 endif;
          											  elseif($type_portfolio=='3') : $image_upload=get_meta_option('image_upload_portfolio',get_the_ID());
          												$direct_url_portfolio=get_meta_option('direct_url_portfolio',get_the_ID());
                                   						
                   								
                           								$return.='<div><a rel="prettyPhoto[iframes]" class="link-icon" href="'.$direct_url_portfolio.'?iframe=true&width=100%&height=100%" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                           						
                           								 endif;
  													 else:
  													
  														$return.='<div><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
  													 endif ;
                                           $return.=' </div>
                                        </div>';
                                       if(!empty($image_thumb)) :
  									  
          							     $return.='<div class="mosaic-backdrop"><img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.$image_thumb[0].'&amp;h=148&amp;w=194&amp;zc=1" alt="'.get_the_title().'"></div>';
                 						
         								   endif;
                              $return.='      </div>                    	
                          		</div>
                              </li>';
		   
	  endwhile;

  	  		   			$return.='	   <li style="overflow: hidden; clear: both; height: 0px; position: relative; float: none; display: block;"></li>
						 </ul>
					</div>';	
endif;
endif;
return $return;
}

function relasted_portfolio_style_2($title='',$enable_title='true',$readmore='',$enable_desc='true',$num_of_post='6',$sort='')
{
//Numofpost
//sort
/* For portfolio style 2
//style
	   //if style portfolio style 2
	   		//enable title
			//readmore
			//Numofchacter
			//showdesc
*/
$types=get_the_terms(get_the_ID(), 'portfolio-types');
//Numofpost
//sort
/* For portfolio style 2
//style
	   //if style portfolio style 2
	   		//enable title
			//readmore
			//Numofchacter
			//showdesc
*/
if($num_of_post == '') :
$num_of_post = get_theme_option('portfolio','portfolio_single_number_related_post');
endif;
if($sort == ''):
$sort = 'ASC';//get_theme_option('portfolio','portfolio_sort');
endif;
if($readmore == ''):
$readmore = get_theme_option('portfolio','portfolio_readmore_link');
endif;
$return;
if($types):
  foreach($types as $type):
  	$slugs[$i]=$type->slug;
  	$i++;
  endforeach;
  $args= array(
  	   		'tax_query' =>array(
         			array(
  				'taxonomy' => 'portfolio-types',
         			'field' => 'slug',
         			'terms' =>$slugs
  				),
         		 ),
  			 'showposts' =>$num_of_post,
  			 'orderby' =>'id',
  			 'order' => $sort,
  			 'post_type' => 'portfolio'
  			 );
  
  global $posts;  
  $posts = new WP_Query( $args );
  
  $return = '';
  if( $posts->have_posts()):
  	
	  		if($title <> ''):
			
			
        		$return='   <div class="right-inner">
                        <h2 class="head">'.$title.'</h2>
            	   </div>';		   
			endif;	  

$curr_count=0;
$sum = 0;
					$return.='<div class="home-blog">
						 <ul id="portfolio-list">';		
while($posts->have_posts()): $posts->the_post();
//Get setting
$image = get_meta_option('image_upload_portfolio',get_the_ID());
$video = get_meta_option('video_embed_code',get_the_ID());
$video_embed=get_meta_option('video_embed_code',get_the_ID());
$youtube_video = get_meta_option('youtube_id',get_the_ID());
$vimeo_video = get_meta_option('vimeo_id',get_the_ID());
$video_style = get_meta_option('video_style',get_the_ID());
$direct_link = get_meta_option('direct_url_portfolio',get_the_ID());
$portfolio_number_chacter =get_theme_option('portfolio','portfolio_number_chacter');

  $sum++;
  $image_thumb = '';
  if(has_post_thumbnail(get_the_ID())):
    $images_id=get_post_thumbnail_id(get_the_ID());
    $image_thumb=wp_get_attachment_image_src($images_id,'194-148');
	$type_portfolio = get_meta_option('portfolio_type',get_the_ID());
  endif;
  $types_portfolio=get_the_terms(get_the_ID(),'portfolio-types');
  $types_portfolio_arr = array();
  $num=0;
  if($types_portfolio) :
     foreach($types_portfolio as $type):
        $types_portfolio_arr[$num]=str_replace(' ','-',$type->name);
        $num++;
     endforeach;
 endif;

                           $return.=' <li class="'.implode(' ',$types_portfolio_arr).'">
                                <div class="blog-shadow">
                                    <div class="blog-img">';
                                         if(!empty($image_thumb)) :
									  
        							     	   $return.=' <img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.$image_thumb[0].'&amp;h=148&amp;w=194&amp;zc=1" alt="'.get_the_title().'">';
               						
       								  	 endif;
                                        $return.='<div class="blog-date">
                                            '.get_the_time('M').' / '.get_the_time('d').'
                                        </div>
                                        
                                    </div>';
									if($enable_title == 'true'):
									
                                     $return.='<h2>'.get_the_title().'</h2>';
                                    	$exceptlength= get_theme_option('portfolio','portfolio_number_chacter'); 
                              		endif;
									if($enable_desc == 'true'):
									
                                    $return.='<p>';
                              		$return.=tt_substr(get_the_excerpt(),$exceptlength);

                              			if($readmore <> '') : 
                              		
									
                              			$return.='<div class="readmore"><a  class="rm-link" href="'.get_permalink(get_the_ID()).'">'.$readmore.'</a></div>
            						</p>';
                              			endif;       
									endif;                       
                                $return.='</div>
                            </li>';
                            
	
endwhile;
  	  		   				   $return.='<li style="overflow: hidden; clear: both; height: 0px; position: relative; float: none; display: block;"></li>
						 </ul>
					</div>';	
endif;
endif;
return $return;
}
#
# Get Popular comment_count
#

function get_postfolio($type='lasted',$title='',$enable_title='true',$readmore='',$enable_desc='true',$num_of_post='6',$sort='')
{
//Numofpost
//sort
/* For portfolio style 2
//style
	   //if style portfolio style 2
	   		//enable title
			//readmore
			//Numofchacter
			//showdesc
*/
if($num_of_post == '') :
$num_of_post = get_theme_option('portfolio','portfolio_single_number_related_post');
endif;
if($sort == ''):
$sort = 'ASC';//get_theme_option('portfolio','portfolio_sort');
endif;
if($readmore == ''):
$readmore = get_theme_option('portfolio','portfolio_readmore_link');
endif;
$orderby='ID';
if($type == 'lasted')
{
 $orderby='ID';
}
else if($type == 'popular')
{
 $orderby='comment_count';
}
  $args= array(
  			 'showposts' =>$num_of_post,
  			 'orderby' =>$orderby,
  			 'order' => $sort,
  			 'post_type' => 'portfolio',
  			 );
  global $posts;  
  $posts = new WP_Query( $args );
  
  $return = '';
  if( $posts->have_posts()):
  	
	  		if($title <> ''):
			
			
        		$return='   <div class="right-inner">
                        <h2 class="head">'.$title.'</h2>
            	   </div>';		   
			endif;	  

$curr_count=0;
$sum = 0;
					$return.='<div class="home-blog">
						 <ul id="portfolio-list">';		
while($posts->have_posts()): $posts->the_post();
//Get setting
$image = get_meta_option('image_upload_portfolio',get_the_ID());
$video = get_meta_option('video_embed_code',get_the_ID());
$video_embed=get_meta_option('video_embed_code',get_the_ID());
$youtube_video = get_meta_option('youtube_id',get_the_ID());
$vimeo_video = get_meta_option('vimeo_id',get_the_ID());
$video_style = get_meta_option('video_style',get_the_ID());
$direct_link = get_meta_option('direct_url_portfolio',get_the_ID());
$portfolio_number_chacter =get_theme_option('portfolio','portfolio_number_chacter');

  $sum++;
  $image_thumb = '';
  if(has_post_thumbnail(get_the_ID())):
    $images_id=get_post_thumbnail_id(get_the_ID());
    $image_thumb=wp_get_attachment_image_src($images_id,'194-148');
	$type_portfolio = get_meta_option('portfolio_type',get_the_ID());
  endif;
  $types_portfolio=get_the_terms(get_the_ID(),'portfolio-types');
  $types_portfolio_arr = array();
  $num=0;
  if($types_portfolio) :
     foreach($types_portfolio as $type):
        $types_portfolio_arr[$num]=str_replace(' ','-',$type->name);
        $num++;
     endforeach;
 endif;

                           $return.=' <li class="'.implode(' ',$types_portfolio_arr).'">
                                <div class="blog-shadow">
                                    <div class="blog-img">';
                                         if(!empty($image_thumb)) :
									  
        							     	   $return.=' <img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.$image_thumb[0].'&amp;h=148&amp;w=194&amp;zc=1" alt="'.get_the_title().'">';
               						
       								  	 endif;
                                        $return.='<div class="blog-date">
                                            '.get_the_time('M').' / '.get_the_time('d').'
                                        </div>
                                        
                                    </div>';
									if($enable_title == 'true'):
									
                                     $return.='<h2>'.get_the_title().'</h2>';
                                    	$exceptlength= get_theme_option('portfolio','portfolio_number_chacter'); 
                              		endif;
									if($enable_desc == 'true'):
									
                                    $return.='<p>';
                              		$return.=tt_substr(get_the_excerpt(),$exceptlength);

                              			if($readmore <> '') : 
                              		
									
                              			$return.='<div class="readmore"><a  class="rm-link" href="'.get_permalink(get_the_ID()).'">'.$readmore.'</a></div>
            						</p>';
                              			endif;       
									endif;                       
                                $return.='</div>
                            </li>';
                            
	
endwhile;
  	  		   				   $return.='<li style="overflow: hidden; clear: both; height: 0px; position: relative; float: none; display: block;"></li>
						 </ul>
					</div>';	
endif;
return $return;
}
function get_portfolio_2($type='lasted',$title='',$num_of_post='',$light_box='',$sort='')
{
wp_enqueue_script('prettyPhoto');
//Numofpost
//lightbox
//sort
/* For portfolio style 2
//style
	   //if style portfolio style 2
	   		//enable title
			//readmore
			//Numofchacter
			//showdesc
*/
$types=get_the_terms(get_the_ID(), 'portfolio-types');
if($light_box == ''):
    $light_box = get_theme_option('portfolio','portfolio_enable_lightbox_related');
endif;
if($num_of_post == '') :
$num_of_post = get_theme_option('portfolio','portfolio_single_number_related_post');
endif;
if($sort == ''):
$sort = get_theme_option('portfolio','portfolio_sort');
endif;

$orderby='ID';

if($type == 'lasted')
{
 $orderby='ID';
}
else if($type == 'popular')
{
 $orderby='comment_count';
}
  $args= array(
  			 'showposts' =>$num_of_post,
  			 'orderby' =>$orderby,
  			 'order' => $sort,
  			 'post_type' => 'portfolio',
  			 );
  global $posts;  
  $posts = new WP_Query( $args );
  
  
  $return = '';
  if( $posts->have_posts()):
  	
	  		if($title <> ''):
			
			$return.='
        		   <div class="right-inner">
                        <h2 class="head">'.$title.'</h2>
            	   </div>';
			endif;	  
	  global $posts;
      $curr_count=0;
      $sum = 0;		
	  					$return.='<div class="home-blog">
						 <ul id="portfolio-list">';						 	
  	  while($posts->have_posts()): $posts->the_post();

            $image = get_meta_option('image_upload_portfolio',get_the_ID());
            $video = get_meta_option('video_embed_code',get_the_ID());
            $video_embed=get_meta_option('video_embed_code',get_the_ID());
            $youtube_video = get_meta_option('youtube_id',get_the_ID());
            $vimeo_video = get_meta_option('vimeo_id',get_the_ID());
            $video_style = get_meta_option('video_style',get_the_ID());
            $direct_link = get_meta_option('direct_url_portfolio',get_the_ID());
			$sum++;
            $image_thumb = '';
            if(has_post_thumbnail(get_the_ID())):
                $images_id=get_post_thumbnail_id(get_the_ID());
                $image_thumb=wp_get_attachment_image_src($images_id,'194-148');
          		$type_portfolio = get_meta_option('portfolio_type',get_the_ID());
            endif;
			  $types_portfolio=get_the_terms(get_the_ID(),'portfolio-types');
              $types_portfolio_arr = array();
              $num=0;
              if($types_portfolio) :
                 foreach($types_portfolio as $type):
                    $types_portfolio_arr[$num]=str_replace(' ','-',$type->name);
                    $num++;
                 endforeach;
             endif;

                           $return.='   <li class="'.implode(' ',$types_portfolio_arr).'">
                                  <div class="port-shadow">
                                    <div class="mosaic-block bar2">
                                        <div class="mosaic-overlay">
                                            <div class="details">
                                                <h2>'.get_the_title().'</h2>';
												
  											   if($light_box=='true'): 
          											   if($type_portfolio=='1') : $image_upload=get_meta_option('image_upload_portfolio',get_the_ID());
                                                         $return.='<div><a rel="prettyPhoto" class="zoom-icon" href="'.$image_upload.'" title="'.get_the_title().'">&nbsp;</a> <a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
          											  elseif($type_portfolio=='2') :
                                                         if($video_style =="embed") :
                                  						
                          						   	    
  														$return.='<div><a rel="prettyPhoto" class="video-icon"   href="#video'.$sum.'" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                                  						
                          								elseif($video_style =="youtube") :
                          								
                          								
                          						  		 $return.='<div><a rel="prettyPhoto" class="video-icon"   href="http://www.youtube.com/watch?v='.$youtube_video.'" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                          								
                          								elseif($video_style =="vimeo") :
                          								
                          								
                          						   		$return.='<div><a href="http://vimeo.com/'.$vimeo_video.'"  class="video-icon" rel="prettyPhoto" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                      									 endif;
          											  elseif($type_portfolio=='3') : $image_upload=get_meta_option('image_upload_portfolio',get_the_ID());
          												$direct_url_portfolio=get_meta_option('direct_url_portfolio',get_the_ID());
                                   						
                   								
                           								$return.='<div><a rel="prettyPhoto[iframes]" class="link-icon" href="'.$direct_url_portfolio.'?iframe=true&width=100%&height=100%" title="'.get_the_title().'"></a><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
                           						
                           								 endif;
  													 else:
  													
  														$return.='<div><a href="'.get_permalink().'" class="link-icon">&nbsp;</a></div>';
  													 endif ;
                                           $return.=' </div>
                                        </div>';
                                       if(!empty($image_thumb)) :
  									  
          							     $return.='<div class="mosaic-backdrop"><img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.$image_thumb[0].'&amp;h=148&amp;w=194&amp;zc=1" alt="'.get_the_title().'"></div>';
                 						
         								   endif;
                              $return.='      </div>                    	
                          		</div>
                              </li>';
		   
	  endwhile;

  	  		   			$return.='	   <li style="overflow: hidden; clear: both; height: 0px; position: relative; float: none; display: block;"></li>
						 </ul>
					</div>';	
endif;
return $return;
}
function tt_get_post($type='lasted',$title='',$enable_title='true',$readmore='',$enable_desc='true',$num_of_post='6',$sort='')
{
//Numofpost
//sort
/* For portfolio style 2
//style
	   //if style portfolio style 2
	   		//enable title
			//readmore
			//Numofchacter
			//showdesc
*/
if($num_of_post == '') :
$num_of_post = get_theme_option('blog','blog_post_per_page');
endif;
if($sort == ''):
$sort = get_theme_option('blog','blog_sort');
endif;
if($readmore == ''):
$readmore = get_theme_option('blog','blog_readmore_link');
endif;
$orderby='ID';
if($type == 'lasted')
{
 $orderby='ID';
}
else if($type == 'popular')
{
 $orderby='comment_count';
}
  $args= array(
  			 'showposts' =>$num_of_post,
  			 'orderby' =>$orderby,
  			 'order' => $sort,
  			 'post_type' => 'post',
  			 );
  global $posts;  
  $posts = new WP_Query( $args );
  
  $return = '';
  if( $posts->have_posts()):
  	
	  		if($title <> ''):
			
			
        		$return='   <div class="right-inner">
                        <h2 class="head">'.$title.'</h2>
            	   </div>';		   
			endif;	  

$curr_count=0;
$sum = 0;
					$return.='<div class="home-blog">
						 <ul id="portfolio-list">';		
while($posts->have_posts()): $posts->the_post();
//Get setting
$portfolio_number_chacter =get_theme_option('blog','blog_except_length');

  $sum++;
  $image_thumb = '';
  if(has_post_thumbnail(get_the_ID())):
    $images_id=get_post_thumbnail_id(get_the_ID());
    $image_thumb=wp_get_attachment_image_src($images_id,'194-148');
	$type_portfolio = get_meta_option('portfolio_type',get_the_ID());
  endif;
  $types_portfolio=get_the_terms(get_the_ID(),'portfolio-types');
  $types_portfolio_arr = array();
  $num=0;
  if($types_portfolio) :
     foreach($types_portfolio as $type):
        $types_portfolio_arr[$num]=str_replace(' ','-',$type->name);
        $num++;
     endforeach;
 endif;

                           $return.=' <li class="'.implode(' ',$types_portfolio_arr).'">
                                <div class="blog-shadow">
                                    <div class="blog-img">';
                                         if(!empty($image_thumb)) :
									  
        							     	   $return.=' <img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.$image_thumb[0].'&amp;h=148&amp;w=194&amp;zc=1" alt="'.get_the_title().'">';
               						
       								  	 endif;
                                        $return.='<div class="blog-date">
                                            '.get_the_time('M').' / '.get_the_time('d').'
                                        </div>
                                        
                                    </div>';
									if($enable_title == 'true'):
									
                                     $return.='<h2>'.get_the_title().'</h2>';
                                    	$exceptlength= get_theme_option('blog','blog_except_length'); 
                              		endif;
									if($enable_desc == 'true'):
									
                                    $return.='<p>';
                              		$return.=tt_substr(get_the_excerpt(),$exceptlength);

                              			if($readmore <> '') : 
                              		
									
                              			$return.='<div class="readmore"><a class="rm-link"  href="'.get_permalink(get_the_ID()).'">'.$readmore.'</a></div>
            						</p>';
                              			endif;       
									endif;                       
                                $return.='</div>
                            </li>';
                            
	
endwhile;
  	  		   				   $return.='<li style="overflow: hidden; clear: both; height: 0px; position: relative; float: none; display: block;"></li>
						 </ul>
					</div>';	
endif;
return $return;
}

//add xiaoming 2012-09-20

function tt_get_post_vedette($type='vedette',$title='',$enable_title='true',$readmore='',$enable_desc='true',$num_of_post='6',$sort='')
{
//Numofpost
//sort
/* For portfolio style 2
//style
	   //if style portfolio style 2
	   		//enable title
			//readmore
			//Numofchacter
			//showdesc
*/
if($num_of_post == '') :
$num_of_post = get_theme_option('blog','blog_post_per_page');
endif;
if($sort == ''):
$sort = get_theme_option('blog','blog_sort');
endif;
if($readmore == ''):
$readmore = get_theme_option('blog','blog_readmore_link');
endif;
$orderby='ID';
if($type == 'vedette')
{
 $orderby='ID';
}
else if($type == 'popular')
{
 $orderby='comment_count';
}
  $args= array(
  			 'showposts' =>$num_of_post,
  			 'orderby' =>$orderby,
  			 'order' => $sort,
  			 'post_type' => 'post',
  			 'tag'=>'vedette',
  			 );
  global $posts;  
  $posts = new WP_Query( $args );
  
  $return = '';
  if( $posts->have_posts()):
  	
	  		if($title <> ''):
			
			
        		$return='   <div class="right-inner">
                        <h2 class="head">'.$title.'</h2>
            	   </div>';		   
			endif;	  

$curr_count=0;
$sum = 0;
					$return.='<div class="home-blog">
						 <ul id="portfolio-list">';		
while($posts->have_posts()): $posts->the_post();
//Get setting
$portfolio_number_chacter =get_theme_option('blog','blog_except_length');

  $sum++;
  $image_thumb = '';
  if(has_post_thumbnail(get_the_ID())):
    $images_id=get_post_thumbnail_id(get_the_ID());
    $image_thumb=wp_get_attachment_image_src($images_id,'194-148');
	$type_portfolio = get_meta_option('portfolio_type',get_the_ID());
  endif;
  $types_portfolio=get_the_terms(get_the_ID(),'portfolio-types');
  $types_portfolio_arr = array();
  $num=0;
  if($types_portfolio) :
     foreach($types_portfolio as $type):
        $types_portfolio_arr[$num]=str_replace(' ','-',$type->name);
        $num++;
     endforeach;
 endif;

                           $return.=' <li class="'.implode(' ',$types_portfolio_arr).'">
                                <div class="blog-shadow">
                                    <div class="blog-img">';
                                         if(!empty($image_thumb)) :
									  
        							     	   $return.=' <img src="'.get_stylesheet_directory_uri().'/timthumb.php?src='.$image_thumb[0].'&amp;h=148&amp;w=194&amp;zc=1" alt="'.get_the_title().'">';
               						
       								  	 endif;
                                        $return.='<div class="blog-date">
                                            '.get_the_time('M').' / '.get_the_time('d').'
                                        </div>
                                        
                                    </div>';
									if($enable_title == 'true'):
									
                                     $return.='<h2>'.get_the_title().'</h2>';
                                    	$exceptlength= get_theme_option('blog','blog_except_length'); 
                              		endif;
									if($enable_desc == 'true'):
									
                                    $return.='<p>';
                              		$return.=tt_substr(get_the_excerpt(),$exceptlength);

                              			if($readmore <> '') : 
                              		
									
                              			$return.='<div class="readmore"><a class="rm-link"  href="'.get_permalink(get_the_ID()).'">'.$readmore.'</a></div>
            						</p>';
                              			endif;       
									endif;                       
                                $return.='</div>
                            </li>';
                            
	
endwhile;
  	  		   				   $return.='<li style="overflow: hidden; clear: both; height: 0px; position: relative; float: none; display: block;"></li>
						 </ul>
					</div>';	
endif;
return $return;
}

 ?>